package projetstackoverflow


abstract class Message {
	
	String content
	Date date
	Author author
	Date editDate
	//static belongsTo = [author:Author]
	static hasMany = [comments:Comment, votes:Vote]
	
	static constraints = {
		content(widget:'textarea')
		content(blank:false)
		editDate(nullable:true)
	}
	
    static mapping = {
		content(type:'text')
	}
	
	public Integer countVotes()
	{
		Integer nb = 0
		for(Vote vote : votes)
		{
			nb += vote.value
		}
		
		return nb
	}
}
